/* GUI CONVERTED from rcbucket.p (converter v1.75) Tue Apr 10 12:03:21 2001 */
/* rcbucket.p - Release Management Customer Schedules                        */
/* Copyright 1986-2002 QAD Inc., Carpinteria, CA, USA.                       */
/* All rights reserved worldwide.  This is an unpublished work.              */
/* $Revision: 1.15 $                                                          */
/*V8:ConvertMode=Report                                                      */
/* REVISION: 7.3    LAST MODIFIED: 10/12/92           BY: WUG *G462*         */
/* REVISION: 7.3    LAST MODIFIED: 03/18/93           BY: WUG *G841*         */
/* REVISION: 7.3    LAST MODIFIED: 06/03/93           BY: WUG *GA75*         */
/* REVISION: 7.3    LAST MODIFIED: 02/14/94           BY: WUG *GI68*         */
/* REVISION: 7.3    LAST MODIFIED: 03/29/94           BY: WUG *GJ22*         */
/* REVISION: 7.3    LAST MODIFIED: 09/11/94           BY: rmh *GM22*         */
/* REVISION: 7.3    LAST MODIFIED: 11/01/94           BY: ame *GN84*         */
/* REVISION: 7.3    LAST MODIFIED: 12/23/94           BY: bcm *G09Y*         */
/* REVISION: 8.6    LAST MODIFIED: 11/14/96           BY: cjt *K01Z*         */
/* REVISION: 8.5    LAST MODIFIED: 04/08/97 BY: *J1NL* Vinay Nayak-Sujir     */
/* REVISION: 8.6E   LAST MODIFIED: 02/23/98 BY: *L007* A. Rahane             */
/* REVISION: 8.6E   LAST MODIFIED: 05/20/98 BY: *K1Q4* Alfred Tan            */
/* REVISION: 8.6E   LAST MODIFIED: 10/04/98 BY: *J314* Alfred Tan            */
/* REVISION: 9.0    LAST MODIFIED: 02/06/99 BY: *M06R* Doug Norton           */
/* REVISION: 9.0    LAST MODIFIED: 03/13/99 BY: *M0BD* Alfred Tan            */
/* REVISION: 9.0    LAST MODIFIED: 08/19/99 BY: *K229* Surekha Joshi         */
/* REVISION: 9.1    LAST MODIFIED: 03/24/00 BY: *N08T* Annasaheb Rahane      */
/* REVISION: 9.1    LAST MODIFIED: 08/12/00 BY: *N0KP* Mark Brown            */
/* REVISION: 9.1    LAST MODIFIED: 09/05/00 BY: *N0R9* Mudit Mehta           */
/* Old ECO marker removed, but no ECO header exists *F0PN*                    */
/* $Revision: 1.15 $    BY: Jean Miller    DATE: 03/22/01 ECO: *P008*        */
/******************************************************************************/
/* All patch markers and commented out code have been removed from the source */
/* code below. For all future modifications to this file, any code which is   */
/* no longer required should be deleted and no in-line patch markers should   */
/* be added.  The ECO marker should only be included in the Revision History. */
/******************************************************************************/

/* BUCKETS A REQUIRED SHIP SCHEDULE */


/*GUI preprocessor directive settings */
&SCOPED-DEFINE PP_GUI_CONVERT_MODE REPORT

{mfdeclre.i}
{gplabel.i} /* EXTERNAL LABEL INCLUDE */

define input parameter sch_recid as recid.
define input parameter report_yn like mfc_logical.

define workfile work_schd like schd_det.
define variable interval as character.
define variable work_dt as date.
define variable work_time as character.
define variable new_cum_qty as decimal.
define variable sch_pos as integer extent 16
   initial [1,9,17,19,21,23,24,25,55,85,88,90,92,150,169,188].
define variable sch_len as integer extent 16
   initial [8,8,2,2,2,1,1,30,30,3,2,2,5,19,19,1].
define variable lastdaysdt as date.
define variable lastweeksdt as date.
define variable lastmthsdt as date.
define variable before like mfc_logical initial yes.
define variable reference as character.
define variable week_offset as integer.
define variable l_msg1 as character no-undo format "x(64)".

find sch_mstr where recid(sch_mstr) = sch_recid
exclusive-lock.

find sod_det where sod_nbr = sch_nbr and
                   sod_line = sch_line
no-lock.

find so_mstr where so_nbr = sod_nbr
no-lock no-error.

if available so_mstr then
   week_offset = integer(substring(so_conrep,1,1)).

if sod_rbkt_days = 0 or sod_rbkt_weeks = 0
then do:
   if report_yn then do:
      {pxmsg.i &MSGNUM=4297 &ERRORLEVEL=1 &MSGBUFFER=l_msg1}
      put
         skip(2)
         l_msg1
         skip(1).
   end.
   leave.
end.

/* Do not rebucket is schedule has AUTHNBRS */
if can-find(first rqm_det
   where rqm_type     = sch_type
   and rqm_nbr      = sch_nbr
   and rqm_line     = sch_line
   and rqm_rlse_id  = sch_rlse_id
   and rqm_cat      = "AUTHNBR")
then do:
   if report_yn then
      put
         skip(2)
         {gplblfmt.i &FUNC=getTermLabel(""FOUND_SCHEDULE"",14)
                     &CONCAT="' '"}
         "AUTHNBRs, "
         {gplblfmt.i &FUNC=getTermLabel(""NO_BUCKETING_DONE"",17)
                     &CONCAT="'.'"}
         skip(1).
   leave.
end.

if report_yn then do:
   {pxmsg.i &MSGNUM=4298 &ERRORLEVEL=1 &MSGBUFFER=l_msg1
      &MSGARG1=string(sod_rbkt_days)
      &MSGARG2=string(sod_rbkt_weeks)
      &MSGARG3=string(sod_rbkt_mths)}
   put unformatted
      skip(2)
      l_msg1
      skip(1).
end.

{gprun.i ""rscalcld.p""
   "(input sch_pcs_date + 1,
     input sod_rbkt_days,
     input sod_rbkt_weeks,
     input sod_rbkt_mths,
     output lastdaysdt,
     output lastweeksdt,
     output lastmthsdt)"}

/* NOW WE CAN BUCKET EVERYTHING */
for each work_schd exclusive-lock:
   delete work_schd.
end.

for each schd_det
   where schd_type = sch_type
     and schd_nbr = sch_nbr
     and schd_line = sch_line
     and schd_rlse_id = sch_rlse_id
exclusive-lock:

   do for work_schd:

      create work_schd.
      assign
         work_schd.schd_date      = schd_det.schd_date
         work_schd.schd_time      = schd_det.schd_time
         work_schd.schd_reference = schd_det.schd_reference
         work_schd.schd_discr_qty = schd_det.schd_discr_qty

         substring(work_schd.schd_fc_qual,1,1) =
         substring(schd_det.schd_fc_qual,1,1).
   end.

   delete schd_det.

end.

for each work_schd no-lock:

   assign
      work_dt = ?
      work_time = ""
      reference = "".

   if schd_date <= lastdaysdt then do:
      assign
         interval = "D"
         work_dt = schd_date
         work_time = schd_time
         reference = schd_reference.
   end.

   else
   if work_schd.schd_date <= lastweeksdt then do:
      /* GET MONDAY OF WEEK THIS DATE IS IN */
      {gprun.i ""rswmd.p""
         "(input schd_date, input before, output work_dt)"}
      interval = "W".
   end.

   else
   if work_schd.schd_date <= lastmthsdt then do:
      /* GET MONDAY OF MONTH THIS DATE IS IN.  NOTE THAT IF THE DATE
       * FALLS  BEFORE THE FIRST MONDAY OF THE MONTH OF THE DATE, WE
       * USE THE DATE OF THE FIRST MONDAY OF THE PRIOR MONTH. */
      {gprun.i ""rsm1md.p""
         "(input schd_date, input before, output work_dt)"}
      interval = "M".
   end.

   if work_dt <> ? then do:

      work_dt = work_dt + week_offset.

      find schd_det where
           schd_det.schd_type = sch_type
       and schd_det.schd_nbr = sch_nbr
       and schd_det.schd_line = sch_line
       and schd_det.schd_rlse_id = sch_rlse_id
       and schd_det.schd_date = work_dt
       and schd_det.schd_time = work_time
       and schd_det.schd_interval = "D"
       and schd_det.schd_reference = reference
      exclusive-lock no-error.

      if not available schd_det then do:
         create schd_det.
         assign
            schd_det.schd_type                   = sch_type
            schd_det.schd_nbr                    = sch_nbr
            schd_det.schd_line                   = sch_line
            schd_det.schd_rlse_id                = sch_rlse_id
            schd_det.schd_date                   = work_dt
            schd_det.schd_time                   = work_time
            schd_det.schd_interval               = "D"
            schd_det.schd_reference              = reference
            substring(schd_det.schd_fc_qual,1,1) = "F".
         recno = recid(schd_det).
      end.

      schd_det.schd_discr_qty = schd_det.schd_discr_qty
                                + work_schd.schd_discr_qty.
   end.

end.

/* UPDATE CUM QUANTITIES */
new_cum_qty = sch_pcr_qty.

for each schd_det
   where schd_type = sch_type
     and schd_nbr = sch_nbr
     and schd_line = sch_line
     and schd_rlse_id = sch_rlse_id
exclusive-lock with frame f-a:

   setFrameLabels(frame f-a:handle).  /* SET EXTERNAL LABELS */

   assign
      new_cum_qty = new_cum_qty + schd_discr_qty
      schd_cum_qty = new_cum_qty.

   if report_yn then do:
      display
         schd_date
         schd_time
         schd_reference
         schd_discr_qty
      with title (getFrameTitle("SCHEDULE_RE-BUCKETED",65)) STREAM-IO /*GUI*/ .
   end.

end.
